package com.geetour.columbus.common.utils;

import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

public class StringUtil {

	public static List<String> lineInput(String str) {
		if (str == null) {
			return null;
		}
		List<String> list = new ArrayList<String>();
		String[] array = str.split("\n");
		for (String s : array) {
			if (s != null && !s.trim().isEmpty()) {
				list.add(s.trim());
			}
		}
		return list;
	}

	public static String convertHTML(String str){
		if(str==null)
			return "";
		str = str.replaceAll("&", "&amp;");
		str = str.replaceAll(">", "&gt;");
		str = str.replaceAll("<", "&lt;");
		return str;
	}

	/**
	 * URL编码
	 * @param str
	 * @return
	 */
	public static String encode(String str){
		try{
			return URLEncoder.encode(str,"UTF-8");
		}catch(Exception e){
			return "";
		}
	}
	/**
	 * URL解码
	 * @param str
	 * @return
	 */
	public static String decode(String str){
		try{
			return URLDecoder.decode(str,"UTF-8");
		}catch(Exception e){
			return "";
		}
	}

}
